<template>
  <div>
    <header>
      <van-nav-bar title="登录" left-text="返回" left-arrow @click-left="$router.go(-1)" />
    </header>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="昵称"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="phone"
        name="手机"
        label="手机"
        placeholder="手机"
        :rules="[{ required: true, message: '请填写您的手机号码！' },
              { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！'}]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import Vue from "vue";
import { Toast } from "vant";

Vue.use(Toast);
export default {
  data() {
    return {
      username: "",
      phone: "",
      password: ""
    };
  },
  methods: {
    onSubmit() {
      this.$store.commit("getuser", {
        username: this.username,
        password: this.password
      });
      this.$router.push("/home");
      Toast.success("登录成功");
    }
  }
};
</script>

<style>
</style>

